﻿using MongoDB.Bson.Serialization.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace InventoryManagementServer
{
    public class User
    {
        private static readonly Dictionary<int, string> keys = new Dictionary<int, string>();

        static User()
	    {
            keys.Add(0, "qxWc9K85EKxBLcNdeawBXZgXQvz3MTZj");
	    }
        
        [BsonId]
        public Guid Id
        {
            get;
            set;
        }

        public string LiveId
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        public string Email
        {
            get;
            set;
        }

        public string Picture
        {
            get;
            set;
        }

        public string AuthenticationToken
        {
            get;
            set;
        }

        public bool Validate()
        {
            JsonWebToken jwt = new JsonWebToken(AuthenticationToken, keys);

            if (jwt.IsExpired)
                return false;

            LiveId = jwt.Claims.UserId;

            return true;
        }
    }
}